
#include "Base.h"
#include "BaseEntity.h"

//#include "Utilities/EventHandler.h"
#include "ComponentMessageEnum.h"
#include "Events/BaseEntityEvents.h"

#include <Memory/DebugNew.h>

namespace CasaEngine
{

	int BaseEntity::m_iNextValidID = 0;

	/**
	 *	setting the ID and incrementing
	 *	the next valid ID
	 */
	BaseEntity::BaseEntity()		
	{
		m_ID = m_iNextValidID;    
		m_iNextValidID++;
		m_pComponentManager = new ComponentManager(this);
	}

	/**
	 *	
	 */
	BaseEntity::~BaseEntity()
	{
		delete m_pComponentManager;
	}

	int BaseEntity::ID() const
	{
		return m_ID;
	}

	/**
	 *	
	 */
	BaseEntity* BaseEntity::GetParent() const 
	{ 
		return m_pParent; 
	}

	/**
	 *	
	 */
	void BaseEntity::SetParent(BaseEntity* val) 
	{ 
		m_pParent = val;

		m_pComponentManager->HandleEvent(new EntityParentChangeEvent);
	}

	/**
	 *	
	 */
	ComponentManager* BaseEntity::GetComponentMgr()
	{ 
		return m_pComponentManager;
	}

	/**
	 * 
	 */
	bool BaseEntity::HandleMessage(const Telegram& msg)
	{
		return m_pComponentManager->HandleMessage(msg);
	}

	/**
	 * 
	 */
	void BaseEntity::Update(const GameTime& gameTime_)
	{
		m_pComponentManager->Update(gameTime_);
	}

	/**
	 * 
	 */
	std::string BaseEntity::GetName() const 
	{ 
		return m_Name; 
	}

	/**
	 * 
	 */
	void BaseEntity::SetName(std::string val) 
	{ 
		m_Name = val; 
	}

	/**
	 * 
	 */
	void BaseEntity::Write(std::ostream& /*os*/) const
	{

	}

	/**
	 * 
	 */
	void BaseEntity::Read (std::ifstream& /*is*/)
	{

	}

	/**
	 * 
	 */
	void BaseEntity::Initialize()
	{
		m_pComponentManager->InitializeComponents();
	}

} // namespace CasaEngine
